package com.jiyuren.wheelview.view;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.jiyuren.wheelview.R;
import com.jiyuren.wheelview.adapter.NumericWheelAdapter;
import com.jiyuren.wheelview.lib.WheelView;

/**
 * 开始时间 --结束时间 com.pickerview.lib.WheelHourMin
 * 
 * @author jiyuren <br/>
 *         create at 2015年5月22日 上午10:20:41
 */
public class WheelDate {
  private View view;
  private WheelView startYear;
  private WheelView startMonth;
  private WheelView endYear;
  private WheelView endMonth;
  public int screenheight;
  
  public View getView() {
    return view;
  }

  public void setView(View view) {
    this.view = view;
  }

  public WheelDate(View view) {
    super();
    this.view = view;
    setView(view);
  }

  public void setTime2TimePicker(List<String> startYearLs, List<String> startMonthLs,
      List<String> endYearLs, List<String> endMonthLs) {
    Context context = view.getContext();

    startYear = (WheelView) view.findViewById(R.id.year_start);
    startYear.setAdapter(new NumericWheelAdapter(startYearLs));
    startYear.setLabel(context.getString(R.string.year));// 添加文字
    startYear.setCurrentItem(0);

    startMonth = (WheelView) view.findViewById(R.id.mon_start);
    startMonth.setAdapter(new NumericWheelAdapter(startMonthLs));
    startMonth.setLabel(context.getString(R.string.month));// 添加文字
    startMonth.setCurrentItem(0);
    
    endYear = (WheelView) view.findViewById(R.id.year_end);
    endYear.setAdapter(new NumericWheelAdapter(endYearLs));
    endYear.setLabel(context.getString(R.string.year));// 添加文字
    endYear.setCurrentItem(0);
    
    endMonth = (WheelView) view.findViewById(R.id.mon_end);
    endMonth.setAdapter(new NumericWheelAdapter(endMonthLs));
    endMonth.setLabel(context.getString(R.string.month));// 添加文字
    endMonth.setCurrentItem(0);

    // 根据屏幕密度来指定选择器字体的大小(不同屏幕可能不同)
    int textSize = (screenheight / 100) * 3;
    startYear.setTextSize(textSize);
    startMonth.setTextSize(textSize);
    endYear.setTextSize(textSize);
    endMonth.setTextSize(textSize);
  }

  /**
   * 设置是否循环滚动
   * 
   * @param cyclic
   */
  public void setCyclic(boolean cyclic) {
    startYear.setCyclic(cyclic);
    startMonth.setCyclic(cyclic);
    endYear.setCyclic(cyclic);
    endMonth.setCyclic(cyclic);
  }
  
  /**
   * 获取时间范围
   * @return
   */
  public String[] getTimeRange(){
    String time[] = new String[4];
    time[0] = (String) startYear.getTextItem(startYear.getCurrentItem());
    time[1] = (String) startMonth.getTextItem(startMonth.getCurrentItem());
    time[2] = (String) endYear.getTextItem(endYear.getCurrentItem());
    time[3] = (String) endMonth.getTextItem(endMonth.getCurrentItem());
    for (int i = 0; i < time.length; i++) {
      Log.i("WheelDate ", "time"+i+" "+time[i]);
    }
    return time;
  }
}
